package com.all.play.myapplication.adapter.inneradapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.all.play.myapplication.Bean.NewsResaultBeanData;
import com.all.play.myapplication.R;
import com.all.play.myapplication.utils.Constants;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2018/4/20.
 * Time: 2018/4/20  14:02
 */

public class MyChannelAdapter extends BaseAdapter {


    private Context mContext;
    private List<NewsResaultBeanData.ResultBean.ChannelInfoBean> channel_info;

    public MyChannelAdapter(Context mContext, List<NewsResaultBeanData.ResultBean.ChannelInfoBean> channel_info) {

        this.mContext = mContext;
        this.channel_info = channel_info;
    }

    @Override
    public int getCount() {
        return channel_info==null?0:channel_info.size();
    }

    @Override
    public Object getItem(int i) {
        return channel_info.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {

        ViewHolder vh;
        if(convertView==null){
            vh=new ViewHolder();
            convertView=View.inflate(viewGroup.getContext(), R.layout.item_channel,null);
            vh.iv_icon= (ImageView) convertView.findViewById(R.id.iv_channel);
            vh.tv_title= (TextView) convertView.findViewById(R.id.tv_channel);
            convertView.setTag(vh);

        }else {
            vh= (ViewHolder) convertView.getTag();

        }
        NewsResaultBeanData.ResultBean.ChannelInfoBean channelInfoBean = channel_info.get(position);
        if(channelInfoBean!=null){
            Glide.with(mContext).load(Constants.BASE_URl_IMAGE+channelInfoBean.getImage()).into(vh.iv_icon);
            vh.tv_title.setText(channelInfoBean.getChannel_name());
        }


        return convertView;
    }


    static class ViewHolder{
        ImageView iv_icon;
        TextView tv_title;
    }
}
